package com.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.Model.Pojo.CunQvKuan;
import com.Model.Pojo.Users;

import com.sql.DAO;

public class CunQvChaXun extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String q = request.getParameter("q");
		
		DAO dao = new DAO();
		HttpSession session = request.getSession(false);
		String sqlyujv = "select * from cunkuanqvkuan where name = '" + ((Users)session.getAttribute("users")).getZhanghao() + "'" + q;
		System.out.println(sqlyujv);
		ArrayList<CunQvKuan> list;
		list = dao.chaxuncunqv(sqlyujv);
		Collections.reverse(list);
		out.println("<table border=’1’ cellspacing=’0’ cellpadding=’5’ class='table table-striped table-bordered table-hover table-condensed'>");
		out.println("<tr><th>存取款ID</th><th>类型(存款/取款)</th><th>操作金额</th><th>操作时间(年-月-日 时:分:秒)</th><th>账户余额</th></tr>");
		for(CunQvKuan cq : list){
			out.print("<tr><td align='center' valign='middle'>" + cq.getId() + "</td><td align='center' valign='center'>" + cq.getStyle() + "</td><td align='center' valign='center'>" + cq.getMoney() + "</td><td align='center' valign='center'>" + cq.getDate() + "</td><td align='center' valign='center'>" + cq.getYue() + "</td></tr>");
		}
		out.print("</table>");
		out.flush();
		out.close();
	}
}
